/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.dashboard.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tianyun.cloud.common.domain.BaseDomain;
import org.tianyun.cloud.common.dto.RestResult;
import org.tianyun.cloud.data.redis.factory.ObjectRedisTemplate;
import org.tianyun.cloud.dashboard.service.RedisCacheTestService;
import org.tianyun.cloud.web.controller.BaseController;

import java.util.List;

/**
 * SampleController
 *
 * @auther ebert_chan
 */
@RestController
@RequestMapping("/")
public class RedisCacheTestController extends BaseController {

    @Autowired
    private RedisCacheTestService redisCacheTestService;

    @Autowired
    private ObjectRedisTemplate objectRedisTemplate;

    @RequestMapping("/redis/set")
    public RestResult<?> redisSet(Long id) {
        List<BaseDomain> value = redisCacheTestService.get(id);
        return success(value);
    }

    @RequestMapping("/redis/get")
    public RestResult<?> redisGet(Long id) {
        List<BaseDomain> value = objectRedisTemplate.get("redis:cache:test:" + (id != null ? id : ""), List.class);
        return success(value);
    }

    @RequestMapping("/redis/flush")
    public RestResult<?> redisFlush(Long id) {
        redisCacheTestService.delete(id);
        return success();
    }

}
